﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using EntityFramework;
using EntityFramework.Extensions;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Data.SystemManager
{
    public class ProductRepository : RepositoryBase<Product>
    {

      

        public IQueryable<ProductTechnologyView> GetProductListByOrderId(Guid orderId)
        {
            decimal tax = Convert.ToDecimal(1.17);
            var result = from order in dbcontext.Orders
                         join op in dbcontext.OrderProducts
                         on order.Id equals op.OrderId
                         join pro in dbcontext.Products
                         on op.ProductId equals pro.Id
                         join cpro in dbcontext.CustomerProducts
                         on new { a = op.ProductId.Value, b = order.CustomeId.Value } equals new { a = cpro.ProductID, b = cpro.CustomerID }
                         into cproTemp
                         from cpro in cproTemp.DefaultIfEmpty()
                         where op.OrderId == orderId
                         select new ProductTechnologyView
                         {
                             ProductId = pro.Id,
                             ProductName = pro.Name,
                             ProductNameOth = cpro.ProductByName,
                             //Type = pro.Type,
                             SizeWidth = pro.SizeWidth,
                             SizeLenth = pro.SizeLenth,
                             Format = pro.Format,
                             Unit = pro.Unit,
                             //Pack = pro.Pack,
                             Amount = op.Amount,
                             Price = op.FinalPrice,
                             TotalPrice = op.Amount * op.Price * tax,
                             OrderId = order.Id,
                         };
            return result;
        }

    }
}
